package sample;

import com.google.gson.*;
import org.dreamwork.gson.EnumTranslator;
import org.dreamwork.gson.GsonHelper;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: seth.yang
 * Date: 14-3-28
 * Time: 下午3:56
 */
public enum TestEnum {
    A /*{
        @Override
        public String getX () {
            return this.getClass ().getName ();
        }
    }*/, B /*{
        @Override
        public String getX () {
            return this.getClass ().getName ();
        }
    }*/, C {
        @Override
        public String getX () {
            return this.getClass ().getName () + " " + this.getClass ().getSuperclass ().getName ();
        }
    };

    public String getX () {return this.getClass ().getName ();}

    /**
     * Returns the name of this enum constant, as contained in the
     * declaration.  This method may be overridden, though it typically
     * isn't necessary or desirable.  An enum type should override this
     * method when a more "programmer-friendly" string form exists.
     *
     * @return the name of this enum constant
     */
    @Override
    public String toString () {
        return "Item " + name ();
    }

/*
    static class P {}
    static class Q extends P {}
    static class T implements JsonSerializer<P>, JsonDeserializer<P> {
        @Override
        public P deserialize (JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
            return new Q ();
        }

        @Override
        public JsonElement serialize (P p, Type type, JsonSerializationContext context) {
            return context.serialize (Q.class.getCanonicalName ());
        }
    }

*/
    public static void main (String[] args) {
/*
        Map<Type, Object> map = new HashMap<Type, Object> ();
        map.put (Q.class, new T ());
*/
        System.out.println (GsonHelper.getGson ().toJson (C));

        for (TestEnum t : TestEnum.values ())
            System.out.println (t.getX ());
    }
}